package org.boyan.modules.cgform.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;

public class l {
    private static String c;

    private static String d;

    private static String e;

    public static String a;

    public static boolean b = true;

    public static String getssss() {
        if ("".equals(d) || d == null) {
            String str = "";
            str = getMa() + getProcessorId() + getMotherboardSN();
            a = n.c(str);
            d = n.c(a.toUpperCase() + getLicTime() + getNetLic() + "P5P5");
        }
        return d.toUpperCase();
    }

    public static String getmachine_code() {
        if ("".equals(d) || d == null) {
            String str = "";
            str = getMa() + getProcessorId() + getMotherboardSN();
            a = n.c(str);
        }
        return a.toUpperCase();
    }

    public static String getssssserver() {
        if ("".equals(e) || e == null) {
            String str = "";
            str = getMa() + getProcessorId() + getMotherboardSN();
            a = n.c(str);
            e = n.c(a.toUpperCase() + getNetLic() + "9999");
        }
        return e.toUpperCase();
    }

    private static String getProcessorId() {
        String str = "CPUID000";
        try {
            Process process = Runtime.getRuntime().exec(new String[] { "wmic", "cpu", "get", "ProcessorId" });
            process.getOutputStream().close();
            Scanner scanner = new Scanner(process.getInputStream());
            String str1 = scanner.next();
            str = scanner.next();
        } catch (Exception exception) {}
        return str;
    }

    private static String a(String paramString) {
        StringBuilder str = new StringBuilder();
        try {
            File file = File.createTempFile("damn", ".vbs");
            file.deleteOnExit();
            FileWriter fileWriter = new FileWriter(file);
            String str1 = "Set objFSO = CreateObject(\"Scripting.FileSystemObject\")\nSet colDrives = objFSO.Drives\nSet objDrive = colDrives.item(\"" + paramString + "\")\nWscript.Echo objDrive.SerialNumber";
            fileWriter.write(str1);
            fileWriter.close();
            Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str2;
            while ((str2 = bufferedReader.readLine()) != null)
                str.append(str2);
            bufferedReader.close();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return str.toString().trim();
    }

    private static String getMotherboardSN() {
        String str = "ZBXLH000";
        try {
            File file = File.createTempFile("realhowto", ".vbs");
            file.deleteOnExit();
            FileWriter fileWriter = new FileWriter(file);
            String str1 = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\nSet colItems = objWMIService.ExecQuery _ \n   (\"Select * from Win32_BaseBoard\") \nFor Each objItem in colItems \n    Wscript.Echo objItem.SerialNumber \n    exit for  ' do the first cpu only! \nNext \n";
            fileWriter.write(str1);
            fileWriter.close();
            Process process = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str2;
            while ((str2 = bufferedReader.readLine()) != null)
                str = str + str2;
            bufferedReader.close();
        } catch (Exception exception) {}
        return str.trim();
    }

    private static String getLicTime() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy");
        return simpleDateFormat.format(new Date());
    }

    public static boolean a() {
        Date date1 = new Date();
        String str = "2015-04-18";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA);
        Date date2 = null;
        try {
            date2 = simpleDateFormat.parse(str);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        assert date2 != null;
        return date2.before(date1);
    }

    private static String getNetLic() {
        String str = "A0001";
        try {
            ResourceBundle resourceBundle =  org.boyan.modules.cgform.util.c.a();
            if (resourceBundle == null)
                resourceBundle = ResourceBundle.getBundle("jeecglic");
            str = resourceBundle.getString("licence.key");
        } catch (Exception exception) {}
        return str;
    }

    private static String getMa() {
        return org.boyan.modules.cgform.util.e.a();
    }

    private static String getMaOld() {
        if (m.c(c)!=0)
            return c;
        String str1 = getOSName();
        String str2 = getSystemRoot() + "/system32/ipconfig /all";
        String str3 = null;
        if (str1.startsWith("windows")) {
            if (str1.equals("windows xp")) {
                str3 = b(str2);
            } else if (str1.equals("windows 2003")) {
                str3 = b(str2);
            } else {
                str3 = getWindow7Ma();
            }
        } else if (str1.startsWith("linux")) {
            str3 = getLinuxMa();
        } else {
            str3 = getUnixMa();
        }
        c = str3;
        return str3;
    }

    private static String getOSName() {
        return System.getProperty("os.name").toLowerCase();
    }

    private static String b(String paramString) {
        String str = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            process = Runtime.getRuntime().exec(paramString);
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {
                if (str1.contains("本地连接"))
                    continue;
                i = str1.toLowerCase().indexOf("physical address");
                if (i != -1) {
                    i = str1.indexOf(":");
                    if (i != -1)
                        str = str1.substring(i + 1).trim();
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null)
                    bufferedReader.close();
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return str;
    }

    private static String getWindow7Ma() {
        InetAddress inetAddress = null;
        try {
            inetAddress = InetAddress.getLocalHost();
        } catch (UnknownHostException unknownHostException) {
            unknownHostException.printStackTrace();
        }
        byte[] arrayOfByte = null;
        try {
            assert inetAddress != null;
            arrayOfByte = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress();
        } catch (SocketException socketException) {}
        StringBuilder stringBuffer = new StringBuilder();
        for (byte b = 0; b < Objects.requireNonNull(arrayOfByte).length; b++) {
            if (b != 0)
                stringBuffer.append("-");
            String str = Integer.toHexString(arrayOfByte[b] & 0xFF);
            stringBuffer.append((str.length() == 1) ? (Character.MIN_VALUE + str) : str);
        }
        return stringBuffer.toString().toUpperCase();
    }

    private static String getLinuxMa() {
        String str = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {
                i = str1.toLowerCase().indexOf("硬件地址");
                if (i != -1) {
                    str = str1.substring(i + 4).trim();
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null)
                    bufferedReader.close();
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return str;
    }

    private static String getUnixMa() {
        String str = null;
        BufferedReader bufferedReader = null;
        Process process = null;
        try {
            process = Runtime.getRuntime().exec("ifconfig eth0");
            bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String str1 = null;
            int i = -1;
            while ((str1 = bufferedReader.readLine()) != null) {
                i = str1.toLowerCase().indexOf("hwaddr");
                if (i != -1) {
                    str = str1.substring(i + "hwaddr".length() + 1).trim();
                    break;
                }
            }
        } catch (IOException iOException) {
            iOException.printStackTrace();
        } finally {
            try {
                if (bufferedReader != null)
                    bufferedReader.close();
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
            bufferedReader = null;
            process = null;
        }
        return str;
    }

    private static String getSystemRoot() {
        String str1 = null;
        String str2 = null;
        String str3 = null;
        String str4 = "windir";
        str2 = System.getProperty("os.name").toLowerCase();
        if (str2.startsWith("windows")) {
            str1 = "cmd /c SET";
        } else {
            str1 = "env";
        }
        try {
            Process process = Runtime.getRuntime().exec(str1);
            InputStreamReader inputStreamReader = new InputStreamReader(process.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String str = null;
            while ((str = bufferedReader.readLine()) != null) {
                str = str.toLowerCase();
                if (str.contains(str4)) {
                    str3 = str.substring(str.indexOf(str4) + str4.length() + 1);
                    return str3;
                }
            }
        } catch (Exception exception) {}
        return null;
    }

    public static String a(String paramString1, String paramString2, String paramString3) {
        Object object = null;
        StringBuilder stringBuffer = new StringBuilder();
        try {
            TrustManager[] arrayOfTrustManager = { new f() };
            SSLContext sSLContext = SSLContext.getInstance("SSL", "SunJSSE");
            sSLContext.init(null, arrayOfTrustManager, new SecureRandom());
            SSLSocketFactory sSLSocketFactory = sSLContext.getSocketFactory();
            URL uRL = new URL(paramString1);
            HttpURLConnection httpURLConnection = (HttpURLConnection)uRL.openConnection();
            httpURLConnection.setConnectTimeout(4500);
            httpURLConnection.setReadTimeout(4500);
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod(paramString2);
            if ("GET".equalsIgnoreCase(paramString2))
                httpURLConnection.connect();
            if (null != paramString3) {
                OutputStream outputStream = httpURLConnection.getOutputStream();
                outputStream.write(paramString3.getBytes(StandardCharsets.UTF_8));
                outputStream.close();
            }
            InputStream inputStream = httpURLConnection.getInputStream();
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String str = null;
            while ((str = bufferedReader.readLine()) != null)
                stringBuffer.append(str);
            bufferedReader.close();
            inputStreamReader.close();
            inputStream.close();
            inputStream = null;
            httpURLConnection.disconnect();
        } catch (ConnectException connectException) {

        } catch (Exception exception) {}
        return stringBuffer.toString();
    }
}
